package com.example.hellodemo.recyclerView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import com.example.hellodemo.R;

public class LinearCyclerViewActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_linear_cycler_view);
        recyclerView = findViewById(R.id.recyclerview1);
        recyclerView.setLayoutManager(new LinearLayoutManager(LinearCyclerViewActivity.this));
        recyclerView.addItemDecoration(new Mydecoration());
        recyclerView.setAdapter(new LinearCyclerAdapter(LinearCyclerViewActivity.this, new LinearCyclerAdapter.OnClickItemListener(){

                    @Override
                    public void onClick(int position) {
                        Toast.makeText(LinearCyclerViewActivity.this,"position:" + position,Toast.LENGTH_SHORT).show();
                    }
                }));
    }
    class Mydecoration extends RecyclerView.ItemDecoration{
        @Override
        public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            outRect.set(0,0,0,getResources().getDimensionPixelOffset(R.dimen.dividerHeight));

        }
    }

}
